package fr.inserm.um915.jimpute.model;

import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;


public class Individual
	{
	public enum Population
		{
		ASW,CEU,CHB,CHS,CLM,FIN,GBR,IBS,JPT,LWK,MXL,PUR,TSI,YRI;
		}
	public enum Group
		{
		AFR,AMR,ASN,EUR;
		}
	
	
	private int index;
	private String name;
	private Population population;
	private Group group;
	private byte sex;
	
	public static class Binding extends TupleBinding<Individual> 
		{
		@Override
		public void objectToEntry(Individual o, TupleOutput out)
			{
			out.writeInt(o.index);
			out.writeString(o.name);
			out.writeByte((byte)o.population.ordinal());
			out.writeByte((byte)o.group.ordinal());
			out.writeByte(o.sex);
			}
			
		@Override
		public Individual entryToObject(TupleInput in)
			{
			int i=in.readInt();
			String s=in.readString();
			Population p=Population.values()[in.readByte()];
			Group g=Group.values()[in.readByte()];
			byte sex=in.readByte();
			return new Individual(i,s,p,g,sex);
			}
		};

	public static final Binding	BINDING=new Binding();
	
	
	public Individual(
				int index, String name, Population population,
			Group group, byte sex) {
		this.index = index;
		this.name = name;
		this.population = population;
		this.group = group;
		this.sex = sex;
		}

	public int getIndex() {
		return index;
	}

	public String getName() {
		return name;
	}

	public Population getPopulation() {
		return population;
	}

	public Group getGroup() {
		return group;
	}

	public byte getSex() {
		return sex;
	}

	@Override
	public int hashCode()
		{
		return name.hashCode();
		}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Individual other = (Individual) obj;
		return name.equals(other.name);
		}
	
	@Override
	public String toString() {
		return this.name;
		}
	
	}
